package com.sbj.controller;

import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sbj.dto.req.CategoryReq;
import com.sbj.dto.res.CategoryRes;
import com.sbj.entity.Category;
import com.sbj.service.CategoryService;
import com.zmh.framework.config.BaseCommonInterface;
import com.zmh.framework.util.Result;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * @author summer
 * @version 1.0
 * @date 2024/8/9 13:52
 */
@RestController
@RequestMapping(value = "/category")
@AllArgsConstructor
public class CategoryController implements BaseCommonInterface<CategoryReq, CategoryRes> {

    private final CategoryService categoryService;

    @Override
    public Result<String> save(@Valid CategoryReq categoryReq) {
        categoryService.saveOrUpdate(Convert.convert(Category.class,categoryReq));
        return Result.successResult();
    }

    @Override
    public Result<String> del(Integer id) {
        categoryService.removeById(id);
         return Result.successResult();
    }

    @Override
    public Result<Page<CategoryRes>> lists(CategoryReq categoryReq) {

        return Result.successResult(categoryService.lists(categoryReq));
    }

    @Override
    public Result<CategoryRes> findById(Integer id) {
        return Result.successResult(Convert.convert(CategoryRes.class,categoryService.getById(id)));
    }

    @Override
    public Result<String> batchDel(List<CategoryRes> list) {
        return null;
    }
}
